package com.ruoyi.system.service.impl;
import com.ruoyi.system.entity.JobFlowRecord;
import com.ruoyi.system.mapper.JobFlowRecordMapper;
import com.ruoyi.system.service.JobFlowRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;


@Service("JobFlowRecordService")
public class JobFlowRecordServiceImpl implements JobFlowRecordService {
    @Resource
    private JobFlowRecordMapper jobFlowRecordRMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JobFlowRecord queryById(Integer id) {
        return this.jobFlowRecordRMapper.queryById(id);
    }

    /**
     * 分页查询
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<JobFlowRecord> queryByPage(JobFlowRecord jobFlowRecord, PageRequest pageRequest) {
        long total = this.jobFlowRecordRMapper.count(jobFlowRecord);
        return new PageImpl<>(this.jobFlowRecordRMapper.queryAllByLimit(jobFlowRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     */
    @Override
    public JobFlowRecord insert(JobFlowRecord jobFlowRecord) {
        this.jobFlowRecordRMapper.insert(jobFlowRecord);
        return jobFlowRecord;
    }

    /**
     * 修改数据
     * @return 实例对象
     */
    @Override
    public JobFlowRecord update(JobFlowRecord jobFlowRecord) {
        this.jobFlowRecordRMapper.update(jobFlowRecord);
        return this.queryById(jobFlowRecord.getId());
    }

    /**
     * 通过主键删除数据
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.jobFlowRecordRMapper.deleteById(id) > 0;
    }
}
